<?php
require 'db_conn.php';
$asql='select * from t_message';
$ajg=$db->query($asql);//$jg就是一个 结果集
$num=$ajg->num_rows;
//设置每页显示几条留言
$page_size=3;
//向上取整,获得最大页码
$max_page=ceil($num/$page_size);
$page=isset($_GET['page'])?$_GET['page']:1;
$pre_page=$page-1;
if($pre_page<1) $pre_page=1;
$next_page=$page+1;
if($next_page>$max_page) $next_page=$max_page;    
$page_html="<a href='index.php?page=1'>首页</a> &nbsp;";
$page_html.="<a href='index.php?page=".$pre_page."'>上一页 </a>&nbsp;";
$page_html.="<a href='index.php?page=".$next_page."'>下一页 </a>&nbsp;";
$page_html.="<a href='index.php?page=$max_page'>尾页 </a>&nbsp;";
$begin=($page-1)*$page_size;
if(!empty($_GET['search'])){
    $searchText=$_GET['search'];
    //Select * from t_message where username like ‘%小%’or message like ‘%小%’;
    $sql="select * from t_message where username like '%".$searchText."%' or message like '%". $searchText."%'";
       
}else{
    // Select * from t_message  limit  (n-1)*5, 5 
$sql='select * from t_message order by id desc limit '.$begin.','.$page_size;

}
$jg=$db->query($sql);//$jg就是一个 结果集
//$num=$jg->num_rows;
while ($row=$jg->fetch_assoc()){
	$rowlist[]=$row;  //所有的结果存放在二维数组$rowlist里面
}
//设置常量，用以判断视图文件是否由此文件加载
define ('BBS','abc');
require 'list_html.php';

